/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fresher.model;

import fresher.objects.Bill;
import fresher.utility.DatabaseUtility;
import fresher.utility.DateConvertUtility;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;

/**
 *
 * @author namlq2
 */
public class BillTotalModel {

    public ArrayList<Bill> getBill(Date begin, Date finish) {
        DatabaseUtility database = new DatabaseUtility();
        String sql = "SELECT * FROM bill";
        ArrayList<Bill> list = new ArrayList<Bill>();
        try {
            ResultSet result = database.query(sql);
            while (result.next()) {
                Bill bill = new Bill(result.getInt(1), result.getInt(2), result.getInt(3), result.getInt(4));
                list.add(bill);
            }

        } catch (SQLException sqlException) {
            database.close();
            return list;
        }
        database.close();
        
        ArrayList<Bill> result = new ArrayList<Bill>();
        for (int i = 0; i < list.size(); i++) {
            Bill bill = list.get(i);
            Date billDate = DateConvertUtility.toDate(bill.getDate());
            if (!billDate.after(finish) && !billDate.before(begin)) {
                result.add(bill);
            }

        }
        return result;
    }
}
